import { Size } from "@/plugins/element";

export const useAppStore = defineStore(
  "app",
  () => {
    const state = reactive({
      sidebar: {
        opened: true // 菜单默认是展开的
      },
      sizeStatus: "default",
      locale: "zh-cn"
    });

    const sidebar = computed(() => state.sidebar);
    const toggleSidebar = () => {
      state.sidebar.opened = !state.sidebar.opened;
    };

    const sizeStatus = computed(() => state.sizeStatus);
    const setSize = (size: Size) => {
      state.sizeStatus = size;
    };

    const locale = computed(() => state.locale);
    return {
      state,
      sidebar,
      toggleSidebar,
      sizeStatus,
      setSize,
      locale
    };
  },
  {
    persist: {
      storage: window.localStorage,
      pick: ["state.sidebar", "state.sizeStatus", "state.locale"]
    }
  }
);
